<?php

/**
 * winbinder 패키지 
 * 
 * 
 * @package php.ui.winbinder
 */


/**
 * WBMenuItem
 *
 * @package php.ui.winbinder
 */
class WBMenuItem extends WBObject { 

	public function __construct($options = array()) { 
		parent::__construct($options);
		
	}

	public function __destruct() {
		parent::__destruct();
	}
	
	public function getMenuTemplate() { 
		return array($this->getOption('id'), $this->getOption('caption'), $this->getOption('hint'), $this->getOption('image'), $this->getOption('accel'));
	}

	public function initMenuItem() { 
		if (isset($this->enabled)) { $this->setEnabled($this->getOption('enabled')); }
		if (isset($this->selected)) { $this->setSelected($this->getOption('selected')); }
	}

	public function initEvent() { 
		parent::initEvent();

		$this->setEvent('click', 'onClick');
	}

	public function fire($eo) { 
		$this->fireEvent('click', $eo);
	}

	public function onClick($eo) { 
		if (isset($this->callback)) { 
			call_user_func_array($this->getOption('callback'), array($eo));
		}
	}
	
	/**
	 * set selected status 
	 * 
	 * @param bool $isSelected
	 */
	public function setSelected($isSelected = false) { 
		$parent = $this->getOption('parent');
		
		if ($parent) { 
			$parent->setSelected($this->getOption('id'), $isSelected);
		}
	}

	/**
	 * 활성 여부 
	 *
	 * @return bool 
	 */
	public function isEnabled() {
		$parent = wbparent($this->getOption('parent'));
		if ($parent) {  
			return wb_get_enabled($parent->getControl($this->getOption('id'))) ;
		}
		
		return false;
	}

	/**
	 * enabled 설정 
	 *
	 * @param bool $enabled
	 */
	public function setEnabled($enabled = true) { 
		$parent = wbparent($this->getOption('parent'));
		if ($parent) {  
			return wb_set_enabled($parent->getControl($this->getOption('id')), $enabled) ;
		}

		return false;		
	}
}

?>
